package com.learn.smart.framework.helper;

import java.util.HashSet;
import java.util.Set;

import com.learn.smart.framework.annotation.Controller;
import com.learn.smart.framework.annotation.Service;
import com.learn.smart.framework.util.ClassUtil;

public class ClassHelper {
		
	@SuppressWarnings("unused")
	private static final Set<Class<?>> CLASS_SET;
	
	static{
		String basePackage = ConfigHelper.getAppBasePackage();
		CLASS_SET = ClassUtil.getClassSet(basePackage);
	}
	
	public static void init(){
		System.out.println("获取所有的class");
	}
	
	public static Set<Class<?>> getControllerClassSet(){
		Set<Class<?>> classSet = new HashSet<Class<?>>();
		for(Class<?> cls : CLASS_SET){
			if(cls.isAnnotationPresent(Controller.class)){
				classSet.add(cls);
			}
		}
		return classSet;
	}
	
	public static Set<Class<?>> getServiceClassSet(){
		Set<Class<?>> classSet = new HashSet<Class<?>>();
		for(Class<?> cls : CLASS_SET){
			if(cls.isAnnotationPresent(Service.class)){
				classSet.add(cls);
			}
		}
		return classSet;
	}
	
	public static Set<Class<?>> getBeanClassSet(){
		Set<Class<?>> classSet = new HashSet<Class<?>>();
		classSet.addAll(getControllerClassSet());
		classSet.addAll(getServiceClassSet());
		return classSet;
	}

}
